package com.webSite.demo.cy;

import java.util.concurrent.Executor;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@SpringBootApplication
@MapperScan(value="com.webSite.demo.cy.mapper")
@ImportResource(locations={"classpath:mykaptcha.xml"})
@EnableAutoConfiguration
@EnableScheduling//开启基于注解的定时任务
//@EnableCaching//基于注解的缓存
//@EnableAsync//异步任务
public class SpringbootCyWebsiteApplication {
	
	public static void main(String[] args) {
		
		SpringApplication.run(SpringbootCyWebsiteApplication.class, args);
	}
	
	/**
	 * 配置线程池(用于异步任务)
	* @Title: threadPoolTaskExecutor  
	* @param @return    参数  
	* @return Executor    返回类型  
	* @throws
	 */
	@Bean(name = "taskExecutor")
    public Executor threadPoolTaskExecutor() {
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);//线程池创建时候初始化的线程数
        executor.setMaxPoolSize(10);//线程池最大的线程数，只有在缓冲队列满了之后，才会申请超过核心线程数的线程
        executor.setQueueCapacity(25);//用来缓冲执行任务的队列
        executor.setKeepAliveSeconds(60);//当超过了核心线程之外的线程，在空闲时间到达之后会被销毁
        executor.setThreadNamePrefix("taskExecutor-");//可以用于定位处理任务所在的线程池
        return executor;
    }
}
